﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using YArchitech.Revit;
using YJKArchUtils.Utils;
using YJKRevitKernel.XYZUtility;
using YJKRevitDimensionText.DimCreator;
using YJKRevitDimensionText.OneKeyPlanDim.LevelDim;

namespace YJKRevitDimensionText.OneKeyPlanDim.Utility
{
	public class OcclusionArea
	{
		public List<CurveLoop> AllComponentOcclusionArea()
		{
			if (this.m_lstAllComponentCurveLoop.Count == 0)
			{
				this.m_lstAllComponentCurveLoop.AddRange(this.m_lstWallCvLoop);
				this.m_lstAllComponentCurveLoop.AddRange(this.m_lstColumnCvLoop);
				this.m_lstAllComponentCurveLoop.AddRange(this.m_lstDoorCvLoop);
				this.m_lstAllComponentCurveLoop.AddRange(this.m_lstWindowsCvLoop);
				this.m_lstAllComponentCurveLoop.AddRange(this.m_lstStairsCvLoop);
				this.m_lstAllComponentCurveLoop.AddRange(this.m_lstOpeningCvLoop);
			}
			return this.m_lstAllComponentCurveLoop;
		}

		public void AddRampCurve(ElementId elemId, List<CurveLoop> lstCv)
		{
			List<CurveLoop> list = null;
			if (!this.m_DicLstRampCurve.TryGetValue(elemId, out list))
			{
				this.m_DicLstRampCurve.Add(elemId, lstCv);
			}
		}

		public List<CurveLoop> AllComponentOcclusionAreaExistRampById(ElementId elemId)
		{
			List<CurveLoop> afterRemoveSameKeyWithElemsLoop = this.GetAfterRemoveSameKeyWithElemsLoop(elemId, this.m_DicLstRampCurve);
			afterRemoveSameKeyWithElemsLoop.AddRange(this.AllComponentOcclusionArea());
			afterRemoveSameKeyWithElemsLoop.AddRange(this.m_lstSlopeDimCvLoop);
			afterRemoveSameKeyWithElemsLoop.AddRange(this.m_lstSizeDimCvLoop);
			afterRemoveSameKeyWithElemsLoop.AddRange(this.m_lstLevelDimCvLoop);
			return afterRemoveSameKeyWithElemsLoop;
		}

		public List<CurveLoop> GetComponentAndSizeAndSlopeOcclusionArea()
		{
			List<CurveLoop> list = OcclusionArea.GetInstance().AllComponentOcclusionArea();
			list.AddRange(OcclusionArea.GetInstance().m_lstSizeDimCvLoop);
			list.AddRange(OcclusionArea.GetInstance().m_lstSlopeDimCvLoop);
			return list;
		}

		private List<CurveLoop> GetAfterRemoveSameKeyWithElemsLoop(ElementId elemId, Dictionary<ElementId, List<CurveLoop>> dic)
		{
			List<CurveLoop> list = new List<CurveLoop>();
			foreach (KeyValuePair<ElementId, List<CurveLoop>> keyValuePair in dic)
			{
				if (elemId == null || keyValuePair.Key != elemId)
				{
					list.AddRange(keyValuePair.Value);
				}
			}
			return list;
		}

		public static OcclusionArea GetInstance()
		{
			if (OcclusionArea.m_Instance == null)
			{
				OcclusionArea.m_Instance = new OcclusionArea();
			}
			return OcclusionArea.m_Instance;
		}

		public static void SetInstanceToNull()
		{
		}

		private OcclusionArea()
		{
		}

		public void CalOcclusionArea()
		{
			this.GetWallCurveLoop();
			this.GetColumnCurveLoop();
			this.GetOpeningCurveLoop();
			this.GetDoorCurveLoop();
			this.GetWindowCurveLoop();
			this.GetIndependentTagCurveLoop();
		}

		public OcclusionArea(Dimension inputDim)
		{
			this.m_dimType = inputDim.DimensionType;
			this.m_dViewScale = (double)inputDim.Document.ActiveView.Scale;
			this.m_dWidthScale = RevitElementExtension.GetParameter(this.m_dimType, BuiltInParameter.TEXT_WIDTH_SCALE).AsDouble();
		}

		public static List<CurveLoop> GetSizeDimCurveLoop(Dimension dimension)
		{
			List<CurveLoop> list = new List<CurveLoop>();
			try
			{
				DimensionType dimensionType = dimension.DimensionType;
				double num = (double)dimension.Document.ActiveView.Scale;
				double num2 = RevitElementExtension.GetParameter(dimensionType, BuiltInParameter.TEXT_WIDTH_SCALE).AsDouble();
				double num3 = RevitElementExtension.GetParameter(dimensionType, BuiltInParameter.TEXT_SIZE).AsDouble() * num;
				double num4 = num3 * num2;
				OcclusionArea.ResetTextStyleSize(RevitElementExtension.GetParameter(dimensionType, BuiltInParameter.TEXT_FONT).AsString(), ref num3, ref num4);
				if (dimension.Curve.GetType() != typeof(Line))
				{
					return list;
				}
				double num5 = 0.0;
				XYZ vt = (dimension.Curve as Line).Direction.Normalize();
				DimensionSegmentArray segments = dimension.Segments;
				if (segments.Size > 0)
				{
					for (int i = 0; i < segments.Size; i++)
					{
                        DimensionSegment dimensionSegment = segments.get_Item(i);
						if (Geometry.IsEqual(num5, 0.0))
						{
							num5 = num4 * (double)OcclusionArea.GetCharNum(dimensionSegment.ValueString);
						}
						CurveLoop sizeDimCurveLoop = OcclusionArea.GetSizeDimCurveLoop(dimensionSegment.Origin, vt, num5, num3, null, true);
						if (sizeDimCurveLoop != null)
						{
							list.Add(sizeDimCurveLoop);
						}
					}
				}
				else
				{
					num5 = num4 * (double)OcclusionArea.GetCharNum(dimension.ValueString);
					CurveLoop sizeDimCurveLoop2 = OcclusionArea.GetSizeDimCurveLoop(dimension.TextPosition, vt, num5, num3, null, true);
					if (sizeDimCurveLoop2 != null)
					{
						list.Add(sizeDimCurveLoop2);
					}
				}
			}
			catch
			{
			}
			return list;
		}

		public bool GetOneDimensionInfo(DimensionSegment inputDimSeg, ref double dTextWidth, ref double dCharHeight)
		{
			try
			{
				dCharHeight = RevitElementExtension.GetParameter(this.m_dimType, BuiltInParameter.TEXT_SIZE).AsDouble() * this.m_dViewScale;
				double num = dCharHeight * this.m_dWidthScale;
				OcclusionArea.ResetTextStyleSize(RevitElementExtension.GetParameter(this.m_dimType, BuiltInParameter.TEXT_FONT).AsString(), ref dCharHeight, ref num);
				dTextWidth = num * (double)OcclusionArea.GetCharNum(inputDimSeg.ValueString);
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		public bool GetOnlyOneDimensionSegmentInfo(string strValue, ref double dTextWidth, ref double dCharHeight)
		{
			try
			{
				dCharHeight = RevitElementExtension.GetParameter(this.m_dimType, BuiltInParameter.TEXT_SIZE).AsDouble() * this.m_dViewScale;
				double num = dCharHeight * this.m_dWidthScale;
				OcclusionArea.ResetTextStyleSize(RevitElementExtension.GetParameter(this.m_dimType, BuiltInParameter.TEXT_FONT).AsString(), ref dCharHeight, ref num);
				dTextWidth = num * (double)OcclusionArea.GetCharNum(strValue);
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		public CurveLoop GetOneDimSegmentCurveBox(DimensionSegment inputDimSeg, XYZ dir, double dTextWidth, double dCharHeight, Autodesk.Revit.DB.View activeView = null)
		{
			CurveLoop result = new CurveLoop();
			try
			{
				result = OcclusionArea.GetSizeDimCurveLoop(inputDimSeg.Origin, dir, dTextWidth, dCharHeight, activeView, false);
			}
			catch (Exception)
			{
				return null;
			}
			return result;
		}

		private static CurveLoop GetSizeDimCurveLoop(XYZ ptLocation, XYZ vt1, double dTextWidth, double dCharHeight, Autodesk.Revit.DB.View activeView = null, bool bIsNeedChangeZ = true)
		{
			CurveLoop result = null;
			try
			{
				XYZ xyz = ptLocation + vt1 * (dTextWidth / 2.0);
				XYZ xyz2 = ptLocation - vt1 * (dTextWidth / 2.0);
				XYZ xyz3 = vt1.CrossProduct(XYZ.BasisY);
				if (vt1.IsAlmostEqualTo(XYZ.BasisY))
				{
					xyz3 = vt1.CrossProduct(XYZ.BasisX);
				}
				else if (vt1.IsAlmostEqualTo(-XYZ.BasisY))
				{
					xyz3 = vt1.CrossProduct(-XYZ.BasisX);
				}
				if (activeView != null)
				{
					xyz3 = activeView.ViewDirection;
				}
				XYZ xyz4 = Geometry.RotateTo(vt1, Math.PI*.5, xyz3).Normalize();
				XYZ xyz5 = xyz + xyz4 * dCharHeight;
				XYZ xyz6 = xyz2 + xyz4 * dCharHeight;
				List<Curve> list = new List<Curve>
				{
					Line.CreateBound(xyz, xyz2),
					Line.CreateBound(xyz2, xyz6),
					Line.CreateBound(xyz6, xyz5),
					Line.CreateBound(xyz5, xyz)
				};
				if (bIsNeedChangeZ)
				{
					result = CommonInterface.GetXYPlaneCurve(CurveLoop.Create(list));
				}
				else
				{
					result = CurveLoop.Create(list);
				}
			}
			catch (Exception)
			{
			}
			return result;
		}

		public static CurveLoop GetSlopeDimCurveLoop(FamilyInstance slopeDim)
		{
			double num = 3.5;
			CurveLoop curveLoop = null;
			try
			{
				double num2 = (double)slopeDim.Document.ActiveView.Scale;
				XYZ xyz = (slopeDim.Location as LocationPoint).Point;
				XYZ xyz2 = slopeDim.HandOrientation.Normalize();
				Parameter parameter = RevitElementExtension.GetParameter(slopeDim, "箭头长度");
				if (parameter == null)
				{
					return curveLoop;
				}
				double num3 = parameter.AsDouble() * num2;
				parameter = RevitElementExtension.GetParameter(slopeDim, "基线长度");
				if (parameter == null)
				{
					return curveLoop;
				}
				double num4 = parameter.AsDouble() * num2;
				parameter = RevitElementExtension.GetParameter(slopeDim, "箭头角度");
				if (parameter == null)
				{
					return curveLoop;
				}
				double num5 = parameter.AsDouble() * num3;
				XYZ xyz3 = slopeDim.FacingOrientation.Normalize();
				xyz -= xyz3 * num5;
				XYZ xyz4 = xyz + xyz2 * (num3 + num4);
				parameter = RevitElementExtension.GetParameter(slopeDim, "坡度值放置间距");
				if (parameter == null)
				{
					return curveLoop;
				}
				double num6 = parameter.AsDouble() * num2;
				XYZ xyz5 = xyz + xyz3 * (num6 + AssistFunc.mmToFeet(num / 2.0) * num2);
				XYZ xyz6 = xyz4 + xyz3 * (num6 + AssistFunc.mmToFeet(num / 2.0) * num2);
				curveLoop = CurveLoop.Create(new List<Curve>
				{
					Line.CreateBound(xyz, xyz4),
					Line.CreateBound(xyz4, xyz6),
					Line.CreateBound(xyz6, xyz5),
					Line.CreateBound(xyz5, xyz)
				});
				curveLoop = CommonInterface.GetXYPlaneCurve(curveLoop);
			}
			catch
			{
			}
			return curveLoop;
		}

		public static CurveLoop GetLevelDimCurveLoop(Autodesk.Revit.DB.Document doc, FamilyInstance levelDim)
		{
			string text = "标高1";
			CurveLoop curveLoop = null;
			try
			{
				double num = (double)levelDim.Document.ActiveView.Scale;
				Parameter parameter = RevitElementExtension.GetParameter(levelDim, text);
				if (parameter == null)
				{
					return curveLoop;
				}
				parameter.AsString();
				Family family = levelDim.Symbol.Family;
				Document document = doc.EditFamily(family);
				List<TextElement> list = (from n in new FilteredElementCollector(document).OfClass(typeof(TextElement))
				select n as TextElement).ToList<TextElement>();
				double num2 = double.MinValue;
				string empty = string.Empty;
				foreach (TextElement textElement in list)
				{
					Parameter parameter2 = RevitElementExtension.GetParameter(textElement, BuiltInParameter.TAG_SAMPLE_TEXT);
					if (parameter2 != null)
					{
						string text2 = parameter2.AsString();
						if (text2.Equals(text) || text2.Equals(text + "\r"))
						{
							Parameter parameter3 = RevitElementExtension.GetParameter(textElement.Symbol, BuiltInParameter.TEXT_SIZE);
							if (parameter3 != null)
							{
								num2 = parameter3.AsDouble();
								break;
							}
						}
					}
				}
				List<DetailCurve> list2 = (from n in new FilteredElementCollector(document).OfClass(typeof(CurveElement))
				where n is DetailCurve
				select n as DetailCurve).ToList<DetailCurve>();
				List<XYZ> list3 = new List<XYZ>();
				for (int i = 0; i < list2.Count; i++)
				{
					for (int j = 0; j < list2.Count; j++)
					{
						IntersectionResultArray intersectionResultArray = null;
						list2[i].GeometryCurve.Intersect(list2[j].GeometryCurve, out intersectionResultArray);
						if (intersectionResultArray != null)
						{
							XYZ ptIntersect = intersectionResultArray.get_Item(0).XYZPoint;
							if (list3.Find((XYZ n) => n.IsAlmostEqualTo(ptIntersect)) == null)
							{
								list3.Add(ptIntersect);
							}
						}
					}
				}
				if (list3.Count < 1)
				{
					return curveLoop;
				}
				list3.Sort(new PointSort());
				XYZ xyz = list3[0];
				List<XYZ> list4 = new List<XYZ>();
				foreach (DetailCurve detailCurve in list2)
				{
					list4.Add(detailCurve.GeometryCurve.GetEndPoint(0));
					list4.Add(detailCurve.GeometryCurve.GetEndPoint(1));
				}
				XYZ zero = XYZ.Zero;
				XYZ zero2 = XYZ.Zero;
				XYZUtilityMethod.GetPolyBoundPts(list4, ref zero, ref zero2);
				XYZ xyz2 = new XYZ(zero.X, zero2.Y, zero.Z);
				XYZ xyz3 = new XYZ(zero2.X, zero.Y, zero2.Z);
				XYZ xyz4 = (xyz2 - zero).Normalize();
				double num3 = xyz2.DistanceTo(zero);
				XYZ xyz5 = zero + xyz4 * (num3 + num2 + AssistFunc.mmToFeet(1.1));
				xyz4 = (zero2 - xyz3).Normalize();
				num3 = zero2.DistanceTo(xyz3);
				XYZ xyz6 = xyz3 + xyz4 * (num3 + num2 + AssistFunc.mmToFeet(1.1));
				try
				{
					List<Curve> list5 = new List<Curve>
					{
						Line.CreateBound(zero * num, xyz3 * num),
						Line.CreateBound(xyz3 * num, xyz6 * num),
						Line.CreateBound(xyz6 * num, xyz5 * num),
						Line.CreateBound(xyz5 * num, zero * num)
					};
					List<Curve> list6 = new List<Curve>();
					XYZ point = (levelDim.Location as LocationPoint).Point;
					double num4 = XYZ.BasisX.AngleTo(levelDim.HandOrientation);
					XYZ xyz7 = XYZ.BasisX.CrossProduct(levelDim.HandOrientation);
					if (!xyz7.IsAlmostEqualTo(XYZ.Zero))
					{
						Transform transform = Transform.CreateRotation(xyz7.Normalize(), num4);
						using (List<Curve>.Enumerator enumerator3 = list5.GetEnumerator())
						{
							while (enumerator3.MoveNext())
							{
								Curve curve = enumerator3.Current;
								list6.Add(curve.CreateTransformed(transform));
							}
							goto IL_48B;
						}
					}
					list6.AddRange(list5);
					IL_48B:
					List<Curve> list7 = new List<Curve>();
					Transform transform2 = Transform.CreateTranslation(point - xyz);
					foreach (Curve curve2 in list6)
					{
						list7.Add(curve2.CreateTransformed(transform2));
					}
					if (list7.Count == 0)
					{
						return curveLoop;
					}
					curveLoop = CurveLoop.Create(list7);
					curveLoop = CommonInterface.GetXYPlaneCurve(curveLoop);
				}
				catch (Exception)
				{
				}
			}
			catch
			{
			}
			return curveLoop;
		}

		private void GetWallCurveLoop()
		{
			List<Element> list = new List<Element>();
			list.AddRange(KeyComponent.GetInstance().m_lstWall);
			OcclusionArea.GetInstance().m_lstWallCvLoop = OcclusionArea.GetFaceCurveLoop(list);
		}

		private void GetColumnCurveLoop()
		{
			List<Element> list = new List<Element>();
			list.AddRange(KeyComponent.GetInstance().m_lstColumn);
			OcclusionArea.GetInstance().m_lstColumnCvLoop = OcclusionArea.GetFaceCurveLoop(list);
		}

		private void GetOpeningCurveLoop()
		{
			new List<Element>();
			Options options = KeyComponent.GetInstance().m_doc.Application.Create.NewGeometryOptions();
			options.ComputeReferences = true;
			options.DetailLevel = (ViewDetailLevel)3;
			foreach (Element element in KeyComponent.GetInstance().m_lstOpening)
			{
				Opening opening = element as Opening;
				if (opening != null)
				{
					OcclusionArea.GetInstance().m_lstOpeningCvLoop.AddRange(OcclusionArea.GetOpeningCurveLoop(opening));
				}
				else if ((element as FamilyInstance).Host is Floor)
				{
					BoundingBoxXYZ boundingBox = element.get_BoundingBox(KeyComponent.GetInstance().m_doc.ActiveView);
					CurveLoop boundingBoxXYZCvLoop = this.GetBoundingBoxXYZCvLoop(boundingBox);
					if (boundingBoxXYZCvLoop != null)
					{
						OcclusionArea.GetInstance().m_lstOpeningCvLoop.Add(boundingBoxXYZCvLoop);
					}
				}
			}
		}

		public static List<CurveLoop> GetOpeningCurveLoop(Opening opening)
		{
			List<CurveLoop> list = new List<CurveLoop>();
			if (opening == null)
			{
				return list;
			}
			try
			{
				List<Curve> list2 = new List<Curve>();
				foreach (object obj in opening.BoundaryCurves)
				{
					Curve curve = (Curve)obj;
					if (!(curve == null))
					{
						if (curve.IsCyclic)
						{
							Arc arc = curve as Arc;
							XYZ xyz = new XYZ(arc.Center.X, arc.Center.Y, 0.0);
							XYZ xyz2 = xyz - new XYZ(arc.Radius, 0.0, 0.0);
							XYZ xyz3 = xyz + new XYZ(arc.Radius, 0.0, 0.0);
							XYZ xyz4 = xyz + new XYZ(0.0, arc.Radius, 0.0);
							XYZ xyz5 = xyz - new XYZ(0.0, arc.Radius, 0.0);
							XYZ xyz6 = new XYZ(xyz2.X, xyz4.Y, 0.0);
							XYZ xyz7 = new XYZ(xyz3.X, xyz4.Y, 0.0);
							XYZ xyz8 = new XYZ(xyz2.X, xyz5.Y, 0.0);
							XYZ xyz9 = new XYZ(xyz3.X, xyz5.Y, 0.0);
							list2.Add(Line.CreateBound(xyz6, xyz7));
							list2.Add(Line.CreateBound(xyz7, xyz9));
							list2.Add(Line.CreateBound(xyz9, xyz8));
							list2.Add(Line.CreateBound(xyz8, xyz6));
						}
						else
						{
							Curve xyplaneCurve = CommonInterface.GetXYPlaneCurve(curve);
							list2.Add(xyplaneCurve);
						}
					}
				}
				list.AddRange(CommonInterface.CreateLoopsByCurves(KeyComponent.GetInstance().m_doc, list2));
			}
			catch
			{
			}
			return list;
		}

		private CurveLoop GetBoundingBoxXYZCvLoop(BoundingBoxXYZ boundingBox)
		{
			XYZ min = boundingBox.Min;
			XYZ max = boundingBox.Max;
			XYZ xyz = new XYZ(min.X, min.Y, 0.0);
			XYZ xyz2 = new XYZ(min.X, max.Y, 0.0);
			XYZ xyz3 = new XYZ(max.X, min.Y, 0.0);
			XYZ xyz4 = new XYZ(max.X, max.Y, 0.0);
			CurveLoop result = null;
			try
			{
				result = CurveLoop.Create(new List<Curve>
				{
					Line.CreateBound(xyz, xyz2),
					Line.CreateBound(xyz2, xyz4),
					Line.CreateBound(xyz4, xyz3),
					Line.CreateBound(xyz3, xyz)
				});
			}
			catch
			{
			}
			return result;
		}

		public void GetIndependentTagCurveLoop()
		{
			List<FamilyInstance> list = new List<FamilyInstance>();
			list.AddRange(KeyComponent.GetInstance().m_lstDoor);
			list.AddRange(KeyComponent.GetInstance().m_lstWindow);
			foreach (FamilyInstance familyInstance in list)
			{
				IndependentTag tag = null;
				if (KeyComponent.GetInstance().m_DicIndependentTag.TryGetValue(familyInstance.Id, out tag))
				{
					CurveLoop independentTagLoop = OcclusionArea.GetIndependentTagLoop(tag, KeyComponent.GetInstance().m_doc);
					if (independentTagLoop != null)
					{
						OcclusionArea.GetInstance().m_lstIndependentTagCvLoop.Add(independentTagLoop);
					}
				}
			}
		}

		public static CurveLoop GetIndependentTagLoop(IndependentTag tag, Autodesk.Revit.DB.Document doc)
		{
			BoundingBoxXYZ boundingBoxXYZ = tag.get_BoundingBox(doc.ActiveView);
			if (boundingBoxXYZ == null)
			{
				return null;
			}
			XYZ xyz = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Max.Y, boundingBoxXYZ.Min.Z);
			XYZ xyz2 = new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Min.Y, boundingBoxXYZ.Max.Z);
			return CurveLoop.Create(new List<Curve>
			{
				Line.CreateBound(boundingBoxXYZ.Min, xyz),
				Line.CreateBound(xyz, boundingBoxXYZ.Max),
				Line.CreateBound(boundingBoxXYZ.Max, xyz2),
				Line.CreateBound(xyz2, boundingBoxXYZ.Min)
			});
		}

		private void GetDoorCurveLoop()
		{
			List<Element> list = new List<Element>();
			list.AddRange(KeyComponent.GetInstance().m_lstDoor);
			OcclusionArea.GetInstance().m_lstDoorCvLoop = OcclusionArea.GetElementCurveLoop(list);
		}

		private void GetWindowCurveLoop()
		{
			foreach (FamilyInstance familyInstance in KeyComponent.GetInstance().m_lstWindow)
			{
				try
				{
					XYZ point = (familyInstance.Location as LocationPoint).Point;
					Parameter parameter = RevitElementExtension.GetParameter(familyInstance.Symbol, "宽度");
					if (parameter != null)
					{
						double num = parameter.AsDouble();
						Element host = familyInstance.Host;
						if (host != null)
						{
							if (host is Wall)
							{
								Wall wall = host as Wall;
								double width = wall.Width;
								XYZ orientation = wall.Orientation;
								XYZ xyz = point + orientation * (width / 2.0);
								XYZ xyz2 = point - orientation * (width / 2.0);
								Curve curve = (wall.Location as LocationCurve).Curve;
								if (!(curve is Arc))
								{
									XYZ direction = (curve as Line).Direction;
									XYZ xyz3 = xyz + direction * (num / 2.0);
									XYZ xyz4 = xyz - direction * (num / 2.0);
									XYZ xyz5 = xyz2 + direction * (num / 2.0);
									XYZ xyz6 = xyz2 - direction * (num / 2.0);
									CurveLoop curveLoop = CurveLoop.Create(new List<Curve>
									{
										Line.CreateBound(xyz3, xyz4),
										Line.CreateBound(xyz4, xyz6),
										Line.CreateBound(xyz6, xyz5),
										Line.CreateBound(xyz5, xyz3)
									});
									if (curveLoop != null)
									{
										OcclusionArea.GetInstance().m_lstWindowsCvLoop.Add(curveLoop);
									}
								}
							}
						}
					}
				}
				catch
				{
				}
			}
		}

		public static List<CurveLoop> GetStairsCurveLoop(Autodesk.Revit.DB.Document doc, Stairs CurStairs)
		{
			List<CurveLoop> list = new List<CurveLoop>();
			CurStairs.GetStairsLandings().ToList<ElementId>();
			List<ElementId> list2 = CurStairs.GetStairsRuns().ToList<ElementId>();
			try
			{
				foreach (ElementId elementId in list2)
				{
					CurveLoop footprintBoundary = (doc.GetElement(elementId) as StairsRun).GetFootprintBoundary();
					if (footprintBoundary != null)
					{
						list.Add(footprintBoundary);
					}
				}
			}
			catch (Exception)
			{
				return null;
			}
			return list;
		}

		private static List<CurveLoop> GetElementCurveLoop(List<Element> lstElems)
		{
			List<CurveLoop> list = new List<CurveLoop>();
			foreach (Element element in lstElems)
			{
				BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null);
				if (boundingBoxXYZ != null)
				{
					XYZ max = boundingBoxXYZ.Max;
					XYZ min = boundingBoxXYZ.Min;
					XYZ xyz = new XYZ(min.X, min.Y, 0.0);
					XYZ xyz2 = new XYZ(min.X, max.Y, 0.0);
					XYZ xyz3 = new XYZ(max.X, min.Y, 0.0);
					XYZ xyz4 = new XYZ(max.X, max.Y, 0.0);
					CurveLoop curveLoop = CurveLoop.Create(new List<Curve>
					{
						Line.CreateBound(xyz, xyz2),
						Line.CreateBound(xyz2, xyz4),
						Line.CreateBound(xyz4, xyz3),
						Line.CreateBound(xyz3, xyz)
					});
					if (curveLoop != null)
					{
						list.Add(curveLoop);
					}
				}
			}
			return list;
		}

		public static List<CurveLoop> GetFaceCurveLoop(List<Element> lstElem)
		{
			List<CurveLoop> list = new List<CurveLoop>();
			foreach (Element element in lstElem)
			{
				List<Face> list2 = new List<Face>();
				try
				{
					Curve curve = ((element as Wall).Location as LocationCurve).Curve;
					OcclusionArea.GetElementFace(ref list2, element, XYZ.BasisZ);
					if (list2 != null && list2.Count != 0)
					{
						if ((list2.Count == 1 && list2.First<Face>().EdgeLoops.Size == 1) || curve is Arc)
						{
							CurveLoop curveLoop = list2.First<Face>().GetEdgesAsCurveLoops().First<CurveLoop>();
							if (curveLoop != null)
							{
								list.Add(CommonInterface.GetXYPlaneCurve(curveLoop));
							}
						}
						else
						{
							double width = (element as Wall).Width;
							if (curve is Line)
							{
								List<Curve> oneDimensionOffsetRange = DimAvoidManager.GetOneDimensionOffsetRange(curve, (curve as Line).Direction, width / 2.0);
								list.Add(CurveLoop.Create(oneDimensionOffsetRange));
							}
						}
					}
				}
				catch (Exception)
				{
				}
			}
			return list;
		}

		private static int GetCharNum(string sText)
		{
			if (sText.Length == 0)
			{
				return 0;
			}
			Encoding encoding = new ASCIIEncoding();
			int num = 0;
			byte[] bytes = encoding.GetBytes(sText);
			for (int i = 0; i < bytes.Length; i++)
			{
				if (bytes[i] == 63)
				{
					num += 2;
				}
				else
				{
					num++;
				}
			}
			return num;
		}

		private static void ResetTextStyleSize(string strTextStyle, ref double dCharHeight, ref double dCharWidth)
		{
			if (strTextStyle.Contains("微软雅黑"))
			{
				dCharHeight *= 1.03;
				dCharWidth *= 0.7;
				return;
			}
			if (strTextStyle.Contains("长仿宋体"))
			{
				dCharHeight *= 0.8;
				dCharWidth *= 0.55;
				return;
			}
			if (strTextStyle.Contains("新宋体") || strTextStyle.Contains("宋体") || strTextStyle.Contains("仿宋") || strTextStyle.Contains("黑体"))
			{
				dCharHeight *= 0.85;
				dCharWidth *= 0.55;
				return;
			}
			dCharHeight *= 1.0;
			dCharWidth *= 0.8;
		}

		private static List<Solid> GetElementSolids(Element element)
		{
			Options options = OcclusionArea.m_doc.Application.Create.NewGeometryOptions();
			options.DetailLevel = (ViewDetailLevel)3;
			options.IncludeNonVisibleObjects = true;
			GeometryElement geometryElement;
			if (element.GetType() == typeof(FamilyInstance))
			{
				FamilyInstance familyInstance = element as FamilyInstance;
				geometryElement = familyInstance.GetOriginalGeometry(options);
				geometryElement = geometryElement.GetTransformed(familyInstance.GetTransform());
			}
			else
			{
				geometryElement = element.get_Geometry(options);
			}
			List<Solid> list = new List<Solid>();
			if (null == geometryElement)
			{
				return list;
			}
			foreach (GeometryObject geometryObject in geometryElement)
			{
				if (!(geometryObject.GetType() != typeof(Solid)))
				{
					Solid solid = geometryObject as Solid;
					if (solid != null)
					{
						list.Add(solid);
					}
				}
			}
			return list;
		}

		public static void GetElementFace(ref List<Face> lstFaces, Element elem, XYZ vtDirection)
		{
			if (elem == null || vtDirection == null)
			{
				return;
			}
			foreach (Solid solid in OcclusionArea.GetElementSolids(elem))
			{
				foreach (object obj in solid.Faces)
				{
					Face face = (Face)obj;
					if (face != null && face is PlanarFace && (face as PlanarFace).FaceNormal.IsAlmostEqualTo(vtDirection))
					{
						lstFaces.Add(face);
					}
				}
			}
		}

		private static OcclusionArea m_Instance;

		public static Document m_doc;

		public List<CurveLoop> m_lstWallCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstColumnCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstOpeningCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstDoorCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstWindowsCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstIndependentTagCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstStairsCvLoop = new List<CurveLoop>();

		private Dictionary<ElementId, List<CurveLoop>> m_DicLstRampCurve = new Dictionary<ElementId, List<CurveLoop>>();

		public List<CurveLoop> m_lstSizeDimCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstSlopeDimCvLoop = new List<CurveLoop>();

		public List<CurveLoop> m_lstLevelDimCvLoop = new List<CurveLoop>();

		private DimensionType m_dimType;

		private double m_dViewScale;

		private double m_dWidthScale;

		private List<CurveLoop> m_lstAllComponentCurveLoop = new List<CurveLoop>();
	}
}
